< previous page page_166 next page >

Page 166
9f31265bb40b592b1929e18a47ab28e5.gif
   intLoop = 1
   Do Until intLoop = 10
      Print intLoop
      intLoop = intLoop + 1
   Loop
End Sub
Loop Until
The Loop Until loop checks the condition at the end of the loop instead of the beginning of the loop, just like Loop While. The statements inside the loop will always be performed at least once. Heres the syntax:
9f31265bb40b592b1929e18a47ab28e5.gif
Do
    <Statement Block>
Loop Until <Cond>
The following example is from the Loop Until command button.
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdLoopUntil_Click ()
   Dim intLoop As Integer

   Cls
   intLoop = 1
   Do
      Print intLoop
      intLoop = intLoop + 1
   Loop Until intLoop = 10
End Sub
For . . . Next
For...Next loops are generally used when you know the exact number of iterations that need to be performed. Youll always use a counter variable that automatically increments or decrements as you iterate through the loop. Because youre using a counter, youll always loop from some start value to some end value. By default, a For...Next loop always increments by one every time through the loop. The value used to stop the loop can be a hard-coded number or a variable. See Figure 8.3 for an example of a For...Next loop.

 
< previous page page_166 next page >

If you like this book, buy it!